#!/usr/bin/python

#Programmer: Aaron Steele
#Date: 2/12/2013
#Purpose: Download codon usage for ~36,000 organisms from kazusa.  Codon
#         usage tabulated from GenBank
#Usage: kazusa_download.py

import urllib2

#All of the codon usage files need from Kazusa
files = ["gbbct.spsum","gbinv.spsum","gbmam.spsum","gbphg.spsum", "gbpln.spsum","gbpri.spsum","gbvrl.spsum","gbvrt.spsum"]

#Open a single file to write all output
outfile_name = "kazusa.spsum"
outfile = open(outfile_name,"w")

#Download each of the files separately and append to file
for f in files:
	print "Downloading " + f
	response = urllib2.urlopen("ftp://ftp.kazusa.or.jp/pub/codon/current/"+f)
	html = response.read()
	outfile.write(html)
	outfile.write("\n")

#Close up the file
outfile.close()

